//
//  MoreManager.m
//  takeout
//
//  Created by Derekc on 12-4-16.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "MoreManager.h"
#import "Constants.h"
#import "ResolveXML.h"

@implementation MoreManager

-(BOOL) sendErrorReport:(NSString *) desc supId:(NSString *) supId contact:(NSString *) contact{
    return [self getResponse:[NSString stringWithFormat:SERVICE_ERROR_REPORT,desc, supId, contact]];
}
-(BOOL) sendFeedBack:(NSString *) desc contact:(NSString *) contact{
    return [self getResponse:[NSString stringWithFormat:SERVICE_FEEDBACK,desc,contact]];    
}
-(BOOL) getResponse:(NSString *) url{
    
    NSString *URIString = [NSString stringWithFormat:SERVICE_DOMAIN, url];
    
    
    
    NSURL *url2 = [[NSURL alloc] initWithString:[URIString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSMutableURLRequest* request = [NSMutableURLRequest new];    
    [request setURL:url2];    
    [request setHTTPMethod:@"GET"]; 
    NSHTTPURLResponse* response;    
    
    
    NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil]; 
    NSString* responseXMLResult=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSError *error;
    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithXMLString: responseXMLResult options:0 error:&error];

    NSArray *children = [doc.rootElement children]; 
    NSString *result = [(GDataXMLElement*)[children objectAtIndex:0] stringValue];
    if ([result isEqualToString:SUCCESS_MSG]) {
        return YES;
    }
    return YES;
}

-(Version *) getVersion{

    NSString *URIString = [[NSString alloc] initWithFormat:SERVICE_DOMAIN, SERVICE_GETVERSION];

    NSURL *url = [[NSURL alloc] initWithString:[URIString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSMutableURLRequest* request = [NSMutableURLRequest new];    
    [request setURL:url];    
    [request setHTTPMethod:@"GET"]; 
    NSHTTPURLResponse* response;    
    
    
    NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil]; 
    NSString* responseXMLResult=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSError *error;
    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithXMLString: responseXMLResult options:0 error:&error];

    NSArray *children = [doc.rootElement children]; 
    Version *version = [[Version alloc] init];
    version.number = [[(GDataXMLElement*)[children objectAtIndex:0] stringValue] floatValue];
    version.description = [(GDataXMLElement*)[children objectAtIndex:1] stringValue];
    return version;
}

@end
